import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router';
import routes from './routes';
// 暂时注释掉这些导入以便测试路由
// import { useUserStore } from '@/stores/useUserStore';
// import { showToast } from 'vant';
// import i18n from '@/locales';

// 创建路由
const router = createRouter({
  history: createWebHashHistory(),
  routes,
  // 平滑滚动
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { top: 0 };
    }
  },
});

// 全局前置守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  const title = to.meta.title as string;
  if (title) {
    document.title = 'Sunny Power';
  }

  // 允许所有导航
  next();
});

export default router; 